$(function(){
	$("#hasAddAppraise,#hasContent").click(function(){
		topage1(1);
		})
	})

function topage1(page){
	$("#thisPage").val(page);
	var hasAddAppraise=0;
	if($("#hasAddAppraise").prop("checked")==true){hasAddAppraise=1;}
	var hasContent=0;
	if($("#hasContent").prop("checked")==true){hasContent=1;}
	var goodsId=$("#goodsId").val();
	$("li.appraiseList").remove();
	$("#loadAppraise").show();
	$.post("/browse/ajaxQueryAppraise",{goodsId:goodsId,page:page,isAppend:hasAddAppraise,hasContent:hasContent},function(data){
		rebuildPage(data.thisPage,data.maxPage);
		setAppraise(data)
		},"json");
}
function turnpage1(){
	var page=$("#pagenum").val();
	$("#thisPage").val(page);
	var hasAddAppraise=0;
	if($("#hasAddAppraise").prop("checked")==true){hasAddAppraise=1;}
	var hasContent=0;
	if($("#hasContent").prop("checked")==true){hasContent=1;}
	var goodsId=$("#goodsId").val();
	$("li.appraiseList").remove();
	$("#loadAppraise").show();
	$.post("/browse/ajaxQueryAppraise",{goodsId:goodsId,page:page,isAppend:hasAddAppraise,hasContent:hasContent},function(data){
		rebuildPage(data.thisPage,data.maxPage);
		setAppraise(data);
		},"json");
}
function rebuildPage(thisPage,maxPage){
	//var thisPage=$("#thisPage").val();
	//var maxPage=$("#maxPage").val();
	var pageHTML="";
	if(thisPage>=2){
		pageHTML+="<a href='javascript:topage1("+(thisPage-1)+")'> < </a>"
	}else{
		pageHTML+="<a href='#'> < </a>"
	}
	if((maxPage-thisPage)>=5){
		pageHTML+="<span class='now'>"+thisPage+"</span><a href='javascript:topage1("+(thisPage+1)+")'>"+(thisPage+1)+"</a><a href='javascript:topage1("+(thisPage+2)+")'>"+(thisPage+2)+"</a><span>…</span><a href='javascript:topage1("+maxPage+")'>"+maxPage+"</a>"
	}else{
		for(var i=4;i>=0;i--){
			if(maxPage-i==thisPage){pageHTML+="<span class='now'>"+(maxPage-i)+"</span>"}
			else if(maxPage-i>0){pageHTML+="<a href='javascript:topage1("+(maxPage-i)+")'>"+(maxPage-i)+"</a>"}
		}
		if(maxPage<=thisPage){
			pageHTML+="<a href='#'> > </a>"
		}else{
			pageHTML+="<a href='javascript:topage1("+(thisPage+1)+")'> > </a>"
		}
		pageHTML+="<font>共"+maxPage+"页</font><form><label>到第</label><input type='text' class='tet' id='pagenum' value=''/><input type='button' value='确定'class='sub' onclick='turnpage1()' id="+maxPage+"/></form>"
	}
	$("http://www.yxit.net/js/div.page").html(pageHTML);
}
function setAppraise(data){
	var appraiseStr="";
	for(var i=0;i<data.appraiseList.length;i++){
		appraiseStr+="<li class='appraiseList'><div id='kuan_s'><p class='first_appraise'>"+data.appraiseList[i].content+"</p><span class='date'><font>"+parseData(data.appraiseList[i].submitDate)+"</font><br/>"+data.appraiseList[i].userVo.teachAddress+" （"+data.appraiseList[i].userVo.nickName+"）</span></div>"
		if((data.appraiseList[i].additionalContent!=""&&data.appraiseList[i].additionalContent!=null)||(data.appraiseList[i].replyContent!=""&&data.appraiseList[i].replyContent!=null)){
			appraiseStr+="<div id='pj_kuan'>";
			if(data.appraiseList[i].additionalContent!=""&&data.appraiseList[i].additionalContent!=null){
			appraiseStr+="<div id='zj_pj'><span>【追加评价】</span><div id='zj_pj_y'>"+data.appraiseList[i].additionalContent+"</div><div id='zj_pj_time'>"+parseData(data.appraiseList[i].additionalDate)+"</div></div>";
			}
			if(data.appraiseList[i].replyContent!=""&&data.appraiseList[i].replyContent!=null){
				appraiseStr+="<div id='huifu'><span>【商家回复】</span><div id='huifu_y'>"+data.appraiseList[i].replyContent+"</div><div id='zj_pj_time'>"+parseData(data.appraiseList[i].replyDate)+"</div></div>"
			}
			appraiseStr+="</div>";
		}
		appraiseStr+="</li>";
	}
	$("#loadAppraise").hide();
	$("#loadAppraise").after(appraiseStr);
}
function parsePhone(phone){
	var str=phone.substring(3,4);
	return phone.replace("str","****");
	}
function parseData(date){
	var localDate=new Date(date);
	var time=localDate.getFullYear()+"-";
	if(localDate.getMonth()<10){
		time+="0";
	}
	time+=(localDate.getMonth()+1)+"-"+localDate.getDate()+" "+localDate.getHours()+":"+localDate.getMinutes()+":"+localDate.getSeconds();
	return time;
}